package plus.easydo.server.user.mp.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import plus.easydo.core.result.R;
import plus.easydo.server.user.mp.qo.SystemLogQo;
import plus.easydo.server.user.mp.service.ISystemLogService;
import plus.easydo.server.user.mp.vo.SystemLogVo;
import plus.easydo.starter.log.annotation.SystemLog;
import plus.easydo.starter.mybatis.plus.base.MPBaseController;
import plus.easydo.starter.mybatis.plus.result.MPDataResult;
import plus.easydo.starter.oauth.resources.anotation.CustomizePreAuthorize;

import java.util.List;


/**
 * 系统日志Controller
 * 
 * @author laoyu
 * @date 2021-12-27 16:07:48
 */
@Api(tags = "系统日志")
@RestController
@RequestMapping("/systemlog")
public class SystemLogController extends MPBaseController {

    @Autowired
    private ISystemLogService systemLogService;

    /**
     * 分页条件查询系统日志列表
     */
    @ApiOperation(value = "分页条件查询系统日志列表")
    @CustomizePreAuthorize(hasPermission = {"system:systemlog:list"})
    @PostMapping("/page")
    public MPDataResult page(@RequestBody SystemLogQo qo) {
        IPage<SystemLogVo> page = systemLogService.page(qo);
        return ok(page);
    }

    /**
     * 获取所有系统日志列表
     */
    @ApiOperation(value = "获取所有系统日志列表")
    @CustomizePreAuthorize(hasPermission = {"system:systemlog:list"})
    @GetMapping("/list")
    public R<List<SystemLogVo>> list(@RequestBody SystemLogQo qo) {
        return ok(systemLogService.list(qo));
    }


    /**
     * 获取系统日志详细信息
     */
    @ApiOperation(value = "获取系统日志详细信息")
    @CustomizePreAuthorize(hasPermission = {"system:systemlog:query"})
    @GetMapping(value = "/{requestId}")
    public R<Object> getInfo(@PathVariable("requestId") Long requestId) {
        return ok(systemLogService.selectById(requestId));
    }

    /**
     * 删除系统日志
     */
    @SystemLog(value = "删除系统日志", saveLog = true)
    @ApiOperation(value = "删除系统日志")
    @CustomizePreAuthorize(hasPermission = {"system:systemlog:remove"})
	@DeleteMapping("/{requestIds}")
    public R<Object> remove(@PathVariable Long[] requestIds) {
        return opResult(systemLogService.deleteByIds(requestIds));
    }

    /**
     * 清空系统日志
     */
    @SystemLog(value = "清空系统日志", saveLog = true)
    @ApiOperation(value = "清空系统日志")
    @CustomizePreAuthorize(hasPermission = {"system:systemlog:clean"})
	@DeleteMapping("/clean")
    public R<Object> clean() {
        return opResult(systemLogService.clean());
    }


}
